types: make Client.on()
compatible with esnext.disposable in TS5.6+
#10773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please describe the changes this PR makes and why it should be merged:
Resolves #10577.
A sticking plaster for v14 to cover this issue, which causes compiler errors when using TS 5.6 or higher under specific conditions. The underlying problem is that the
EventEmitter.on()
iterator now extends AsyncIteratorObject in TS 5.6+, which becomes an AsyncDisposable if lib.esnext.disposable is loaded, whereas the override signature in the v14 types uses the older AsyncIterableIterator, which isn't AsyncDisposable and so causes an assignability mismatch.AsyncIteratorObject doesn't exist in TypeScript 5.5 and earlier, so this change provides a custom AsyncIterableIterator interface that matches whether the return type of the parent
EventEmitter.on()
is AsyncDisposable or not.This isn't future-proof against any further changes to the TS iterator types, but this only really needs to hold until v15 ships, and this seems like the least invasive fix.
It's not possible to test this fix within the tsd tests, as the package dependencies use neither an affected version of TypeScript nor an affected version of @types/node; however, manual tests confirm it to be working as intended.
Status and versioning classification: